<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<md-dialog class="promote-api-dialog">
  <form name="formApiPromotion" ng-submit="$ctrl.promote()" novalidate ng-if="$ctrl.hasCockpit">
    <md-dialog-title class="promote-api-dialog__title"><h4>Promote the API</h4></md-dialog-title>
    <md-dialog-content class="promote-api-dialog__content">
      <div ng-if="$ctrl.isLoading" class="promote-api-dialog__content__loading">
        <md-progress-circular></md-progress-circular>
        <div class="promote-api-dialog__content__loading__text">Fetching environments...</div>
      </div>
      <div ng-if="!$ctrl.isLoading">
        <div ng-if="$ctrl.promotionTargets.length > 0">
          <div>Select the environment to which you want to promote the API</div>
          <div class="promote-api-dialog__content__environments">
            <md-radio-group ng-model="$ctrl.selectedPromotionTarget">
              <md-radio-button ng-repeat="env in $ctrl.promotionTargets" ng-value="env" ng-disabled="env.promotionInProgress">
                <div>{{env.name}}<span ng-if="env.promotionInProgress">*</span></div>
              </md-radio-button>
            </md-radio-group>
          </div>
          <div class="promote-api-dialog__content__promotion-in-progress" ng-if="$ctrl.hasPromotionInProgress">
            <div>* A promotion to this environment is already in progress.</div>
            <div>It should be accepted or rejected before being able to create a new one.</div>
          </div>
        </div>
        <div ng-if="$ctrl.promotionTargets.length === 0" class="promote-api-dialog__content__no-environment">
          <gv-icon shape="general:settings#1"></gv-icon>
          <div class="promote-api-dialog__content__environments">No environment is available for API promotion.</div>
        </div>
      </div>
    </md-dialog-content>
    <md-dialog-actions>
      <md-button ng-click="$ctrl.hide()">Cancel</md-button>
      <md-button type="submit" class="md-primary" ng-disabled="!$ctrl.selectedPromotionTarget">Promote</md-button>
    </md-dialog-actions>
  </form>

  <div ng-if="!$ctrl.hasCockpit" class="promote-api-dialog__meet-cockpit">
    <md-dialog-title class="promote-api-dialog__meet-cockpit__title"><h4>Meet Cockpit</h4></md-dialog-title>
    <md-dialog-content class="promote-api-dialog__meet-cockpit__content">
      <span></span>
      <img
        class="promote-api-dialog__meet-cockpit__content__logo"
        ng-src="{{'assets/gravitee_cockpit_logo.png'}}"
        alt="Logo of Gravitee.io Cockpit"
      />
      <p>
        <a ng-href="{{$ctrl.cockpitURL}}" target="_blank">Cockpit</a> is a centralized, multi-tenancy tool for monitoring all your
        Gravitee.io installations from one handy interactive dashboard.
      </p>
      <p>
        Create an account on <a ng-href="{{$ctrl.cockpitURL}}" target="_blank">Cockpit</a>, register your current installation and start
        promoting your APIs across multiple environments!`.
      </p>
    </md-dialog-content>

    <md-dialog-actions>
      <md-button class="md-primary" ng-click="$ctrl.hide()">OK</md-button>
    </md-dialog-actions>
  </div>
</md-dialog>
